<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib uri="/struts-tags" prefix="s"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<jsp:include page="/admin/common/css/style_sub.jsp"></jsp:include>
<script type="text/javascript" src="<%=basePath%>js/lib/jquery/jquery-1.7.1.min.js"></script>
<script type="text/javascript" src="<%=basePath%>js/public.js"></script>
<script language="javascript">
$(function(){
	
});

//更新用户状态
function updateUserState(userId, ustate){
	var params = {
			ct : getCurrentTime(),
			'user.id': userId,
			'user.ustate': ustate
	};
	$.getJSON('<%=basePath%>basic/sys/user_updateUserState.action', params, function(json){
		if(json.resultCode == 'success'){
			alert("改变用户状态成功！");
			$('#searchBtn').click();
		}else{
			alert("改变用户状态失败，请联系管理员！");
		}
	});
}

//重置用户密码
function resetPassword(userId){
	var params = {
			ct : getCurrentTime(),
			'user.id': userId
	};
	$.getJSON('<%=basePath%>basic/sys/user_resetPassword.action', params, function(json){
		if(json.resultCode == 'success'){
			alert("重置用户密码成功！");
		}else{
			alert("重置用户密码失败，请联系管理员！");
		}
	});
}

function gotoUserPosition(userId, orgId){
	var url = '<%=basePath%>basic/sys/user_gotoUserPosition.action?user.id=' + userId + '&user.org_id=' + orgId;
	window.location.href = url
}

function gotoUserRole(userId){
	var url = '<%=basePath%>basic/sys/user_gotoUserRole.action?user.id=' + userId;
	window.location.href = url
}

function chooseOrgan(){
	var url = '<%=basePath%>admin/basic/system/dep/organ_choose.jsp'; 
	window.callback = fillOrgan;
	openModalWindow(url, window, 'small');
}

function fillOrgan(orgId, orgName){
	$('input[name="user.org_id"]').val(orgId);
	$('input[name="user.org_name"]').val(orgName);
}
</script>
</head>
<body>
	<form action="<%=basePath%>basic/sys/user_selectUser.action" id="sf" method="post">
		<div class="searchTab">
			<table>
				<tr>
					<th>登录账号</th>
					<td>
						<input type="text" name="user.uname" value="${user.uname}"/>
					</td>
					<th>用户姓名</th>
					<td>
						<input type="text" name="user.rname" value="${user.rname}"/>
					</td>
					<td></td>
				</tr>
				<tr>
					<th>所属部门</th>
					<td>
						<a href="javascript:void(0);" onclick="chooseOrgan();">
							<input type="text" readonly="readonly" name="user.org_name" value="${user.org_name}" readonly="readonly"/>
							<img src="<%=basePath%>style/images/ico_11.gif" />
						</a>
						<input type="hidden" name="user.org_id" value="${user.org_id}"/>
					</td>
					<th>用户状态</th>
					<td>
						<label><input type="radio" name="user.ustate" value="1" <s:if test="%{user.ustate == 1}">checked="checked"</s:if>/>
						<img src="<%=basePath%>style/icons/ok.png" title="启用" alt="启用"/></label>&nbsp;&nbsp;&nbsp;&nbsp;
						<label><input type="radio" name="user.ustate" value="2" <s:if test="%{user.ustate == 2}">checked="checked"</s:if>/>
						<img src="<%=basePath%>style/icons/pause.png" title="停用" alt="停用"/></label>
					</td>
					<td>
						<span class="btn"><input type="submit" id="searchBtn" value="查询"/></span>
						<span class="btn">
							<input type="button" value="新增用户" 
								onclick="javascript:window.location.href = '<%=basePath%>admin/basic/system/user/user_add.jsp'"/>
						</span>
					</td>
				</tr>
			</table>
		</div>
		<!--查询条件表格-->
		<div class="listTab">
			<table>
				<thead>
					<tr>
						<td>登录账号</td>
						<td>用户姓名</td>
						<td>所属部门</td>
						<td>担任职务</td>
						<td>手机号码</td>
						<td>状态</td>
						<td>操作</td>
					</tr>
				</thead>
				<tbody>
					<s:iterator value="%{pm.list}">
					<tr>
						<td class="tdLeft">${uname}</td>
						<td class="tdLeft">${rname}</td>
						<td class="tdLeft">${org_name}</td>
						<td class="tdLeft">${position_name}</td>
						<td class="tdLeft">${uphone}</td>
						<td>
							<s:if test="%{ ustate==1}">
								<img src="<%=basePath%>style/icons/ok.png" title="启用" alt="启用"/>
							</s:if>
							<s:elseif test="%{ustate==2}">
								<img src="<%=basePath%>style/icons/pause.png" title="停用" alt="停用"/>
							</s:elseif>
						</td>
						<td>
							<a href="javascript:void(0);" class="add" onclick="gotoUserRole(${id});">赋角色</a>
							<a href="javascript:void(0);" class="set" onclick="gotoUserPosition(${id}, ${org_id});">添加职务</a>
							<a href="javascript:void(0);" class="return" onclick="resetPassword(${id});">重置密码</a>
							<a href="<%=basePath%>basic/sys/user_selectByUserID.action?user.id=${id}" class="modi">编辑</a>
							<s:if test="%{ustate==1}">
								<a href="javascript:void(0);" class="disc" onclick="updateUserState(${id}, 2);">停用</a>
							</s:if>
							<s:else>
								<a href="javascript:void(0);" class="enable" onclick="updateUserState(${id}, 1);">启用</a>
							</s:else>
						</td>
					</tr>
					</s:iterator>
					<s:if test="%{pm.list.size() == 0}">
					<tr>
						<td colspan="7"><font>暂时没有内容信息</font></td>
					</tr>
					</s:if>
				</tbody>
			</table>
		</div>
		<s:if test="%{pm.list.size() > 0}">
		<jsp:include page="/admin/common/pagemodel.jsp"></jsp:include>
		</s:if>
	</form>
</body>
</html>
